package com.gopay.scheduler.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.domain.cust.CustSettledInfo;
import com.gopay.scheduler.dao.MerchantSettledInfoDAO;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * Created by liyang on 2017/4/12.
 */
@Repository("merchantSettledInfoDAO")
public class MerchantSettledInfoDAOImpl extends BaseDAOImpl<CustSettledInfo, Serializable> implements MerchantSettledInfoDAO {
    /**
     * 通过商户ID查询商户入驻信息
     *
     * @param custId
     * @return
     */
    @Override
    public List<CustSettledInfo> getCustSettledInfoByCustId(String custId) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
        criteria.add(Restrictions.eq("custId", custId));
        List<CustSettledInfo> list = this.findByCriteria(criteria);
        return list;
    }

    /**
     * 通过商户ID和入驻类型(微信或者支付宝)查询商户入驻信息
     *
     * @param custId
     * @param type
     * @return
     */
    @Override
    public CustSettledInfo getCustSettledInfoByCustIdAndType(String custId, String type) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
        criteria.add(Restrictions.eq("custId", custId));
        criteria.add(Restrictions.eq("type", type));
        List<CustSettledInfo> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public CustSettledInfo getCustSettledInfo(String custId, String type, String stat) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
        criteria.add(Restrictions.eq("custId", custId));
        criteria.add(Restrictions.eq("type", type));
        criteria.add(Restrictions.eq("stat", stat));
        List<CustSettledInfo> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public CustSettledInfo getCustSettledInfoByPram(String merchantCode, String type) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
        criteria.add(Restrictions.eq("merchantCode", merchantCode));
        criteria.add(Restrictions.eq("type", type));
        List<CustSettledInfo> list = this.findByCriteria(criteria);
        return list.size() > 0 ? list.get(0) : null;
    }

    @Override
    public List<CustSettledInfo> getCustSettledInfoByState(String stat) {
        DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
        criteria.add(Restrictions.eq("stat", stat));
        List<CustSettledInfo> list = this.findByCriteria(criteria);
        return list;
    }
}
